package com.kingyun.gpsinspection.purificationservice.services.tdm.innerservice.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.tdm.TaskDependencyMapper;
import com.kingyun.gpsinspection.purificationservice.facade.model.tdm.TaskDependency;
import com.kingyun.gpsinspection.purificationservice.facade.model.tdm.TaskDependencyVo;
import com.kingyun.gpsinspection.purificationservice.facade.service.tdm.TaskDependencyService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by jiangjx on 2017/1/19.
 * 任务依赖关系管理service实现
 */
public class TaskDependencyServiceImpl implements TaskDependencyService {

    @Autowired
    private TaskDependencyMapper taskDependencyMapper;

    /**
     * 根据条件加载table数据
     *
     * @param taskDependencyVo 查询条件封装类
     * @return
     */
    @Override
    public JSONObject loadTaskDependencyList(TaskDependencyVo taskDependencyVo) {
        /*装载查询条件*/
        taskDependencyVo.setLimit(null == taskDependencyVo.getLimit() ? 10 : taskDependencyVo.getLimit());
        taskDependencyVo.setOffset(null == taskDependencyVo.getOffset() ? 0 : taskDependencyVo.getOffset());
        JSONObject jsonObject = new JSONObject();
        /* 进行分页查询分离 */
        jsonObject.put("total", taskDependencyMapper.queryCount(taskDependencyVo));//查询总条数
        List<TaskDependency> baseRows = taskDependencyMapper.queryTableList(taskDependencyVo);//查询分页内容
        /*返回结果*/
        jsonObject.put("rows", JSON.toJSON(baseRows));
        return jsonObject;
    }
}
